package zhihuilan.controlle.wechatMini;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhihuilan.common.WxMiniResponse;
import zhihuilan.common.enums.ResultEnum;
import zhihuilan.controlle.BasicController;
import zhihuilan.dto.MyStaffShopGoodsDto;
import zhihuilan.dto.WxMiniPageDto;
import zhihuilan.entity.MyGoods;
import zhihuilan.params.query.MyGoodsQueryParam;
import zhihuilan.params.query.MyStaffShopGoodsQueryParam;
import zhihuilan.service.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * 小程序端API </p>
 * 接口说明：</p>
 *
 * @Module 会员商品接口模块
 * @Author chenk
 * @Version 1.0.1 (2025-02-24)
 */
@Slf4j
@RestController
@RequestMapping("/app/Goods")
public class MyGoodsController extends BasicController {

    @Resource
    private MyGoodsService myGoodsService;

    @Autowired
    private MyStaffShopGoodsService myStaffShopGoodsService;

    /**
     * getGoodsList_会员商品-获取会员商品列表；
     *
     * @param queryParam  会员商品查询参数【MyGoodsQueryParam】；
     * @return 标准响应体封装基础返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getGoodsList")
    public WxMiniResponse getGoodsList(@RequestBody MyGoodsQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        queryParam.setStatus(1);
        List<MyGoods> list = this.myGoodsService.selectList(queryParam.getType(), queryParam.getCategory(), queryParam.getStatus());
        return WxMiniResponse.ok(list);
    }


    /**
     * getGoodsInfo_会员商品-获取会员商品列表；
     *
     * @param queryParam  会员商品查询参数【MyGoodsQueryParam】；
     * @return 标准响应体封装基础返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getGoodsInfo")
    public WxMiniResponse getGoodsInfo(@RequestBody MyGoodsQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if(ObjectUtils.isEmpty(queryParam.getId())){
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(),"参数id为空");
        }
        MyGoods goods = this.myGoodsService.selectGoodsInfoById(queryParam.getId());
        return WxMiniResponse.ok(goods);
    }

    @PostMapping("/getStaffGoodsList")
    public WxMiniResponse getStaffGoodsList(@RequestBody MyStaffShopGoodsQueryParam queryParam){
        System.out.println(queryParam);
      WxMiniPageDto<MyStaffShopGoodsDto> staffShopGoodsWxMiniPageDto = myStaffShopGoodsService.selectMyStaffShopGoodsList(queryParam);
//      WxMiniPageDto<MyStaffShopGoodsDto> goodsDtoWxMiniPageDto = new WxMiniPageDto(staffShopGoodsWxMiniPageDto.getCurrent(),staffShopGoodsWxMiniPageDto.getSize());
//      List<MyStaffShopGoodsDto> list = staffShopGoodsWxMiniPageDto.getData().stream().map(po->{
//          MyStaffShopGoodsDto myStaffShopGoodsDto = new MyStaffShopGoodsDto();
//          BeanUtils.copyProperties(po, myStaffShopGoodsDto);
//          return myStaffShopGoodsDto;
//      }).collect(Collectors.toList());
//      goodsDtoWxMiniPageDto.setData(list);
//      goodsDtoWxMiniPageDto.setTotal(staffShopGoodsWxMiniPageDto.getTotal());
       return WxMiniResponse.ok(staffShopGoodsWxMiniPageDto);
    }

}
